package com.mage.completeproject.mapper;

import com.mage.completeproject.bean.Department;
import org.apache.ibatis.annotations.*;

import java.util.List;

//@Mapper或者@MapperScan将接口扫描装配到容器中,使用MapperScan批量扫描所有的Mapper接口，也使得@Autowired自动装配Mapper接口对象能够成功,这两个注解指定这是一个操作数据库的mapper
//在spring主类上添加注解@MapperScan(value = "com.mage.springboot.mapper")，相似于@SpringBootApplication
public interface DepartmentMapper {
    @Select("SELECT * FROM department")
    List<Department> getDeptAll();

    @Select("SELECT * FROM department WHERE id=#{id}")
    Department getDeptById(Integer id);

    @Delete("DELETE FROM department WHERE id=#{id}")
    int deleteDeptById(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("INSERT INTO department(department_name) VALUES(#{departmentName})")
    int insertDept(Department department);

    @Update("UPDATE department SET department_name=#{departmentName} WHERE id=#{id}")
    int updateDept(Department department);
}
